#include "StdAfx.h"
#include "LabelPanelUI.h"
#include "BlueRenderEngineUI.h"

CLabelPanelUI::CLabelPanelUI(void): m_cxWidth(0), m_uTextStyle(DT_VCENTER)
{
}

CLabelPanelUI::~CLabelPanelUI(void)
{
}

LPCTSTR CLabelPanelUI::GetClass() const
{
	return _T("LabelPanelUI");
}

void CLabelPanelUI::SetText(LPCTSTR pstrText)
{
	// Automatic assignment of keyboard shortcut
	if( _tcschr(pstrText, '&') != NULL ) m_chShortcut = *(_tcschr(pstrText, '&') + 1);
	CControlUI::SetText(pstrText);
	//Invalidate();
}

void CLabelPanelUI::SetWidth(int cx)
{
	m_cxWidth = cx;
	UpdateLayout();
}

void CLabelPanelUI::SetTextStyle(UINT uStyle)
{
	m_uTextStyle = uStyle;
	Invalidate();
}

void CLabelPanelUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
{
	if( _tcscmp(pstrName, _T("align")) == 0 ) {
		if( _tcsstr(pstrValue, _T("center")) != NULL ) m_uTextStyle |= DT_CENTER;
		if( _tcsstr(pstrValue, _T("right")) != NULL ) m_uTextStyle |= DT_RIGHT;
	}
	else if( _tcscmp(pstrName, _T("width")) == 0 ) SetWidth(_ttoi(pstrValue));
	else CControlUI::SetAttribute(pstrName, pstrValue);
}

SIZE CLabelPanelUI::EstimateSize(SIZE /*szAvailable*/)
{
	return CStdSize(m_cxWidth, m_pManager->GetThemeFontInfo(UIFONT_NORMAL).tmHeight + 4);
}

void CLabelPanelUI::DoPaint(HDC hDC, const RECT& rcPaint)
{
	RECT rcText;
	rcText.top = m_rcItem.top;
	rcText.bottom = m_rcItem.bottom;
	rcText.left = m_rcItem.left;
	rcText.right = m_rcItem.right;
	/*RECT rcText;
	rcText.top = 325;
	rcText.bottom = 365;
	rcText.left = 3;
	rcText.right = 150;*/


	int nLinks = 0;
	CBlueRenderEngineUI::DoPaintPrettyText(hDC, m_pManager, rcText, m_sText, 
		UICOLOR_EDIT_TEXT_NORMAL, UICOLOR__INVALID, NULL, nLinks,  m_uTextStyle & ~DT_SINGLELINE);
}

